package com.example.blog.common.pojo;

import com.example.blog.common.enums.ResultStatusEnum;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/7/25
 * Time: 17:41
 */
@Data
public class Result<T> {
    private int code;
    private String errMsg;
    private T data;

    public static <T> Result<T> ok(T data) {
        Result result = new Result();
        result.setCode(ResultStatusEnum.SUCCESS.getCode());
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultStatusEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> fail(String errMsg, T data) {
        Result result = new Result();
        result.setCode(ResultStatusEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
